package no.sachmuld.methodcombination.demo;

import no.sachmuld.aspectjattach.AspectJAgent;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.WebAppContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletException;
import java.awt.*;
import java.net.URI;

/**
 *
 */
public class JettyStarter {

    public static void main(String[] args) throws Exception {

        AspectJAgent.initializeIfNeeded();

        Server server = new Server(8080);
        WebAppContext webAppContext = new WebAppContext(server, "src/main/webapp", "/mc");
        webAppContext.addEventListener(new ServletContextListener() {
            @Override
            public void contextInitialized(ServletContextEvent sce) {
                try {
                    new DemoInitializer().onStartup(null, sce.getServletContext());
                } catch (ServletException e) {
                    throw new RuntimeException(e);
                }
            }

            @Override
            public void contextDestroyed(ServletContextEvent sce) {
                // noop
            }
        });
        server.setHandler(webAppContext);
        server.start();
        Desktop.getDesktop().browse(new URI("http://localhost:8080/mc/demo"));
        server.join();
    }

}
